package com.project.controller;

import com.project.bean.UserBean;
import org.apache.catalina.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.time.LocalDate;

@RestController
@RequestMapping("test")
public class TestController {
    @RequestMapping("speak")
    public String speak(){
        return "ok";
    }

    @RequestMapping("getUser")
    public UserBean getUser(){
        return new UserBean(1,"张三", LocalDate.parse("2001-03-11"),20000);
    }

    @RequestMapping("add")
    public UserBean add(UserBean user){
        return user;
    }


    @RequestMapping("register")
    public String register(String name, @RequestParam("face")MultipartFile mf) throws IOException {
        String fileName = mf.getOriginalFilename();
        mf.transferTo(new File("d:/下载目录/java课下载/face/"+fileName));

        return "ok,"+name+","+fileName;
    }

    @RequestMapping("land")
    public String land(String userName, String pwd, HttpServletRequest request){
        if ("java".equals(userName)&&"123".equals(pwd)) {
            request.getSession().setAttribute("loginUser", userName);
            return "ok";
        }
        return "登录失败";
    }
}
